#coding=utf-8?
from .course import Course

# 课程集合
class Courses():
    def __init__(self, name):
        self.name = name

        self.title = []
        self.courses = []

        self.period_all = 0  # 总学时
        self.credit_all = 0  # 总学分
        self.period_tech = 0  # 理论学时
        self.period_prac = 0 # 实践学时
        self.period_prac_in = 0  # 课内实践
        self.period_prac_out = 0  # 课外实践
        self.center_week_all = 0
        self.semester = [{},{},{},{},{},{},{},{},{}]  # 学期计数

        self.titleDict = {}

    def initCoursesInfo(self, data):
        for i in range(len(data)):
            self.titleDict[data[i]] = i

    def addCourse(self, data):
        course = Course(self.titleDict)
        self.courses.append(course)
        #if self.name.find(u"集中") >=0 or self.name.find(u"第") >=0:
        #    course.loadPractiseCenter(data, len(self.courses))
        #else:
        course.load(self.titleDict, data, len(self.courses))

    def updateSummit(self):
        self.period_all = 0;  # 总学时
        self.credit_all = 0;  # 总学分
        self.period_tech = 0;  # 理论学时
        self.period_prac = 0    # 实践学时
        self.period_prac_in = 0;# 课内实践
        self.period_prac_out = 0;# 课外实践
        self.Course_proportions = {
            "人文社会科学类": {
                "credit": 0.0,
                "period": 0,
                "credit_proportion": 0.0
            },
            "自然科学类": {
                "credit": 0.0,
                "period": 0,
                "credit_proportion": 0.0
            },
            "工程实践与毕业设计": {
                "credit": 0.0,
                "period": 0,
                "credit_proportion": 0.0
            },
            "工程基础类与专业类": {
                "credit": 0.0,
                "period": 0,
                "credit_proportion": 0.0
            }
        }

        for s in self.semester:
            s['credit'] = 0
            s['period'] = 0
            s['period_in'] = 0
            s['kaoshi'] = []
            s['kaocha'] = []
            s['otherclass']=[]

        for c in self.courses:
            if c.groupMask:
                self.period_all += int(c.get("学时数"))
                self.credit_all += c.get("学分数")
                self.period_tech += int(c.get("理论"))
                self.period_prac_in += c.period_prac_in
                self.period_prac_out += c.period_prac_out
                self.period_prac += c.period_prac
                self.center_week_all += c.get("实践周数")

                if c.dictData['人文社会科学类'] == 1.0:
                    self.Course_proportions['人文社会科学类']["credit"] += c.dictData['学分数']
                    self.Course_proportions['人文社会科学类']["period"] += c.dictData['学时数']
                elif c.dictData['自然科学类'] == 1.0:
                    self.Course_proportions['自然科学类']["credit"] += c.dictData['学分数']
                    self.Course_proportions['自然科学类']["period"] += c.dictData['学时数']
                elif c.dictData['工程实践与毕业设计'] == 1.0:
                    self.Course_proportions['工程实践与毕业设计']["credit"] += c.dictData['学分数']
                    self.Course_proportions['工程实践与毕业设计']["period"] += c.dictData['学时数']
                elif c.dictData['工程基础类与专业类'] == 1.0:
                    self.Course_proportions['工程基础类与专业类']["credit"] += c.dictData['学分数']
                    self.Course_proportions['工程基础类与专业类']["period"] += c.dictData['学时数']
                if c.semester >=0 and c.semester <= 8:
                    self.semester[c.semester]['credit'] += c.get("学分数")
                    self.semester[c.semester]['period'] += c.get("学时数")
                    self.semester[c.semester]['period_in'] += c.get("学时数")-c.get("课外实践")-c.get("线上")
                    if c.get("考核方式") == '考试':
                        self.semester[c.semester]['kaoshi'].append(c.name)
                    elif c.get("考核方式") == '考查':
                        self.semester[c.semester]['kaocha'].append(c.name)
                    else:
                        self.semester[c.semester]['otherclass'].append(c.name)
                else:
                    print("Error: c.semester >=0 and c.semester <= 7")

    def showSummit(self):
        print(self.name)
        print(self.period_all, "总学时");
        print(self.credit_all, "总学分");
        print(self.period_tech, "理论学时");
        print(self.period_prac_in, "实践学时");
        print(self.period_prac_out, "课内实践");
        print(self.semester, "课外实践");

    # def Courseproportions(self):
    #     self.

if __name__ == '__main__':
    pass